package priv.books.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import priv.books.mapper.AdminMapper;
import priv.books.pojo.Admin;
import priv.books.pojo.Books;
import priv.books.pojo.BooksType;
import priv.books.pojo.OrderDetail;

@Service
public class AdminService extends ServiceImpl<AdminMapper, Admin> {

    @Autowired
    private AdminMapper adminMapper;

    /**
     * 查询登录信息
     * @param admin
     * @return
     */
    public Admin getLoginInfo(Admin admin) {
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<Admin>();
        queryWrapper.eq("user_name", admin.getUserName());
        queryWrapper.eq("password", admin.getPassword());
        return adminMapper.selectOne(queryWrapper);
    }

    /**
     * 查询所有信息
     * @param admin
     * @return
     */
//    public List<Admin> getAllInfo(Admin admin) {
//        QueryWrapper<Admin> queryWrapper = new QueryWrapper();
//        return adminMapper.selectList(queryWrapper);
//    }

    public List<Admin> getAllInfo(Admin admin) {
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        if(admin != null) {
            queryWrapper.like(!StrUtil.isBlankOrUndefined(admin.getUserName()), "user_name", admin.getUserName());
        }
        return adminMapper.selectList(queryWrapper);
    }



}
